<?php
/**
 * Doctrine CLI runner
 */
define('BASE_PATH', dirname(__FILE__));
chdir(BASE_PATH);

function __autoload($class)
{
    $class = str_replace('Admin_', 'models_', $class);
    $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
    include_once realpath(BASE_PATH . DIRECTORY_SEPARATOR . $file);
}

$manager = Doctrine_Manager::getInstance();

$dsn = 'sqlite:admin.db.sqlite';
$manager->openConnection($dsn);

$manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
$manager->setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, true);
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
$manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_TABLES);

Doctrine::loadModel('Admin_Doctrine_User', 'models/Doctrine/User.php');
Doctrine::loadModel('Admin_Doctrine_Role', 'models/Doctrine/Role.php');
Doctrine::loadModel('Admin_Doctrine_UserRole', 'models/Doctrine/UserRole.php');
Doctrine::loadModel('Admin_Doctrine_RoleHeirarchy', 'models/Doctrine/RoleHeirarchy.php');
Doctrine::loadModel('Admin_Doctrine_Permission', 'models/Doctrine/Permission.php');

$config = array('data_fixtures_path'  =>  'doctrine',
                'models_path'         =>  'models/Doctrine',
                'migrations_path'     =>  'doctrine',
                'sql_path'            =>  'doctrine',
                'yaml_schema_path'    =>  'doctrine');

$cli = new Doctrine_Cli($config);
$cli->run($_SERVER['argv']);